﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Wicresoft.Common;
using JDEduTrain.Framework.Entity;
using JDEduTrain.Framework.Business;

public partial class Page_AuditClassDetail : BaseAuthenticationPage
{
    public Guid ClassID
    {
        get
        {
            if (Request["ClassID"] != null)
                return new Guid(Request["ClassID"]);
            return Guid.Empty;
        }
    }

    public bool IsAudit
    {
        get
        {
            if (Request["IsAudit"] != null)
                return bool.Parse(Request["IsAudit"]);
            return false;
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        this.UseTabber = true;
        if (!IsPostBack)
        {
            BindClass();
            if (IsAudit)
            {
                tblOperator.Visible = false;
            }
            DataTable dtOrder = BLTrain.GetOrderByClassID(ClassID);
            ddlOrder.DataSource = dtOrder;
            ddlOrder.DataTextField = "OrderName";
            ddlOrder.DataValueField = "ID";
            ddlOrder.DataBind();

        }
    }

    protected void BindClass()
    {
        TrainClass trainClass = new TrainClass(ClassID);
        if (trainClass.Load())
        {
            tbBeginTime.Text = trainClass.BeginTime.ToShortDateString();
            tbClassName.Text = trainClass.ClassName;
            tbComment.Text = trainClass.Comment;
            tbEndTime.Text = trainClass.EndTime.ToShortDateString();
            tbScore.Text = trainClass.Score.ToString();
            tbPlace.Text = trainClass.Place;
            tbLectorInfo.Text = trainClass.LectorInfo;
            tbCourseInfo.Text = trainClass.CourseInfo;
            tbTrainLevel.Text = trainClass.TrainLevel;
            tbHostUnit.Text = trainClass.HostUnit;
            tbTrainDay.Text = trainClass.TrainDayCount.ToString();
            tbCurriculum.Text = HttpUtility.HtmlDecode(trainClass.Curriculum);
            tbDeptDisplayName.Text = trainClass.ApplyOrgan;
        }

        BindOrder();
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindClass();
    }
    protected void btnAttendClass_Click(object sender, EventArgs e)
    {
        ClassMember member = new ClassMember(CurrentUser.ID, ClassID);
        TrainClass trainClass = new TrainClass(ClassID);
        string script;
        if (member.Load())
        {
            script = "alert('您已报名！');";
        }
        else
        {
            if (ddlOrder.SelectedValue != "请选择")
            {
                member.OrderID = new Guid(ddlOrder.SelectedValue);
            }
            member.MemberName = CurrentUser.DisplayName;
            member.MemberAccount = CurrentUser.Name;
            member.TotalScore = 0;
            member.StudyTime = 0;
            if (trainClass.Load() && trainClass.ClassName.Contains("中心组学习"))
            {
                member.Status = "终审通过";
            }
            else
            {
                member.Status = "待审核";
            }
            member.Save();
            script = "alert('报名成功！');";
        }
        Page.ClientScript.RegisterStartupScript(GetType(), "alert", script, true);
    }

    protected void BindOrder()
    {

        DataTable dtOrder = BLTrain.GetOrderByClassID(ClassID);
        rptOrderInfo.DataSource = dtOrder;
        rptOrderInfo.DataBind();

    }


}
